<?php
use think\Db;

use app\portal\model\PortalCategoryPostModel;
/** PC端文章类列表*/
function get_list($id){
    $model = new PortalCategoryPostModel();
    $list = $model->with('post')->where('status',1)->where('category_id', $id)->paginate(10);
    return $list;
}
/** mobile 列表不分页*/
function get_mobile_list($id){
    $model = new PortalCategoryPostModel();
    $list = $model->with('post')->where('status',1)->where('category_id', $id)->select();
    return $list;
}

function add_sys_log($content,$type){
	return Db::name('sys_log')->insertGetId([
		'content'=>$content,
		'type'=>$type
	]);
}

function _httpPost($url="" ,$requestData){
                
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POST, 1);
        //普通数据
        curl_setopt($curl, CURLOPT_POSTFIELDS,$requestData);
        $res = curl_exec($curl);
        curl_close($curl);
        return $res;
    }


function send_sms_mas($mobile,$msg,$from="系统"){

	$time_formatted = date('Y-m-d H:i:s',time());
	$url  = 'http://112.35.1.155:1992/sms/norsubmit'; 

	$ecName = '日照市公安局交通警察支队';
	$appId = 'shuke';
	$secretKey = 'coolaring';
	$sign = 'YmxEhFrC';
	$mac= md5($ecName.$appId.$secretKey.$mobile.$msg.$sign); //mac计算
	$para = [
		"ecName"=>$ecName,
		"apId"=> $appId,
		"mobiles"=> $mobile,
		"content"=> $msg,
		"sign"=> $sign,
		"addSerial"=>'',
		"mac"=>$mac

	]; //打包参数，直接发送
	$para = base64_encode(json_encode($para));
	$response = _httpPost($url,$para);
	$result = json_decode($response,true);
	$log = "[$time_formatted] [$from]发送给[$mobile]短信息，内容为：$msg,接口返回详情：$response";
	add_sys_log($log,6);
}